//
//  ViewController.m
//  textLoginView
//
//  Created by liuchengming on 16/10/17.
//  Copyright © 2016年 liuchengming. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    //UIlabel的设置
    _lbUesrName = [UILabel new] ;
    _lbPassword = [UILabel new] ;
    
    _lbUesrName.frame = CGRectMake(20, 60, 80, 44);
    _lbPassword.frame = CGRectMake(20, 140, 80, 44);
    _lbUesrName.text = @"用户名:";
    _lbPassword.text = @"密码:";
    _lbUesrName.font = [UIFont systemFontOfSize:15];
    _lbPassword.font = [UIFont systemFontOfSize:15];
    _lbUesrName.textAlignment = NSTextAlignmentLeft ;
    _lbPassword.textAlignment = NSTextAlignmentLeft ;
    
    //UITextFirld 的设置
    _tfUserName = [UITextField new];
    _tfUserName.frame = CGRectMake(120, 60, 150, 44);
    _tfUserName.placeholder = @"请输入用户名";
    _tfUserName.borderStyle = UITextBorderStyleRoundedRect ;
    
    _tfPassword = [UITextField new];
    _tfPassword.frame = CGRectMake(120, 140, 150, 44);
    _tfPassword.placeholder = @"请输入密码";
    _tfPassword.borderStyle = UITextBorderStyleRoundedRect ;
    _tfPassword.secureTextEntry = YES ;
    
    
    //UIButton的设置
    _btLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect] ;
    _btLogin.frame = CGRectMake(120, 300, 80, 44);
    [_btLogin setTitle:@"登陆" forState:UIControlStateNormal];
    [_btLogin addTarget:self action:@selector(pressLogin) forControlEvents:UIControlEventTouchUpInside];
    
    _btRegister = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    _btRegister.backgroundColor = [UIColor grayColor];
    _btRegister.frame = CGRectMake(120, 360, 80, 44);
    [_btRegister setTitle:@"注册" forState:UIControlStateNormal];
    [_btRegister addTarget:self action:@selector(pressRegister) forControlEvents:UIControlEventTouchUpInside];
    
    //添加到视图
    [self.view addSubview:_lbUesrName];
    [self.view addSubview:_lbPassword];
    [self.view addSubview:_tfUserName];
    [self.view addSubview:_tfPassword];
    [self.view addSubview:_btLogin];
    [self.view addSubview:_btRegister];

}

//登陆事件
-(void) pressLogin
{
    //拟定的用户名
    NSString * strName = @"Interesting";
    NSString * strPass = @"123456" ;
    
    //获取TextField中的文字
    NSString * strTextName = _tfUserName.text;
    NSString * strTextPass = _tfPassword.text;
    
    if ([strName isEqualToString:strTextName] && [strPass isEqualToString:strTextPass])
    {
        UIAlertView * alView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"登陆成功！！" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [alView show];
    }else{
        UIAlertView * alView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"登陆失败，请检查用户名！" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [alView show];
    }
}

//注册事件
-(void) pressRegister
{
    
}

//点击空白收回键盘
-(void) touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [_tfUserName resignFirstResponder];
    [_tfPassword resignFirstResponder];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
